package com.cswangdao.controller.admin;//package com.cswangdao.adminservlet;

import com.cswangdao.domain.dto.*;
import com.cswangdao.domain.model.*;
import com.cswangdao.domain.po.User;
import com.cswangdao.result.PageResult;
import com.cswangdao.result.Result;
import com.cswangdao.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author YL
 * @description: 用户管理模块
 * @date 2024/8/22 9:27
 */
@RequestMapping("/admin")
@RestController
@Slf4j
public class UserManagementController {


    @Autowired
    private UserService userService;

    @Autowired
    private AddressService addressService;

    @Autowired
    private CollectService collectService;

    @Autowired
    private FootprintService footprintService;

    @Autowired
    private FeedbackService feedbackService;

    @Autowired
    private SearchHistoryService searchHistoryService;


    /**
     * @description: 分页查询用户列表
     * @param: request, response
     * @return: void
     */
    @GetMapping("/user/list")
    public Result<PageResult<User>> user(UserPageDTO userPageDTO) {
        log.info("分页查询用户列表:{}", userPageDTO);
        PageResult<User> userList = userService.pageQueryInfo(userPageDTO);
        return Result.success(userList);
    }

    @GetMapping("/user/detail")
    public Result<User> userDetail(Integer id) {
        log.info("查询用户详情:{}", id);
        User user = userService.getUserById(id);
        return Result.success(user);
    }

    @PostMapping("/user/update")
    public Result<User> userUpdate(@RequestBody User user) {
        log.info("更新用户信息:{}", user);
        User updateUser = userService.updateById(user);
        return Result.success(updateUser);
    }

    /**
     * @description: 分页查询地址列表
     * @param: request, response
     * @return: void
     */
    @GetMapping("/address/list")
    public Result<PageResult<MarketAddress>> address(AddressPageDTO addressPageDTO) {
        log.info("分页查询地址列表:{}", addressPageDTO);
        PageResult<MarketAddress> pageResult = addressService.pageQueryInfo(addressPageDTO);
        return Result.success(pageResult);
    }

    /**
     * @description: 分页查询收藏列表
     * @param: request, response
     * @return: void
     */
    @GetMapping("/collect/list")
    public Result<PageResult<MarketCollect>> collect(CollectPageDTO collectPageDTO) {
        log.info("分页查询收藏列表:{}", collectPageDTO);
        PageResult<MarketCollect> pageResult = collectService.pageQueryInfo(collectPageDTO);
        return Result.success(pageResult);
    }

    /**
     * @description: 分页查询足迹列表
     * @param: request, response
     * @return: void
     */
    @GetMapping("/footprint/list")
    public Result<PageResult<MarketFootprint>> footprint(FootprintDTO pageDTO) {
        log.info("分页查询足迹列表:{}", pageDTO);
        PageResult<MarketFootprint> pageResult = footprintService.pageQueryInfo(pageDTO);
        return Result.success(pageResult);
    }

    /**
     * @description: 分页查询搜索历史列表
     * @param: request, response
     * @return: void
     */
    @GetMapping("/history/list")
    public Result<PageResult<MarketSearchHistory>> history(SearchHistoryDTO pageDTO) {
        log.info("分页查询搜索历史列表:{}", pageDTO);
        PageResult<MarketSearchHistory> pageResult = searchHistoryService.pageQueryInfo(pageDTO);
        return Result.success(pageResult);
    }

    /**
     * @description: 分页查询反馈列表
     * @param: request, response
     * @return: void
     */
    @GetMapping("/feedback/list")
    public Result<PageResult<MarketFeedback>> feedback(FeedbackPageDTO pageDTO) {
        log.info("分页查询反馈列表:{}", pageDTO);
        PageResult<MarketFeedback> pageResult = feedbackService.pageQueryInfo(pageDTO);
        return Result.success(pageResult);
    }
}
